﻿using UnityEngine;
using UnityEngine.UI;

public class CellUI : MonoBehaviour
{
    public GameUI m_GameUI;
    public Cell m_TargetCell;
    public GameObject m_BluePiece;
    public GameObject m_RedPiece;
    public Text m_Text;

    public void DisplayCell()
    {
        if (!m_TargetCell.m_Empty)
        {
            if (m_TargetCell.m_BelongTo == Player.Blue)
            {
                m_BluePiece.SetActive(true);
                m_RedPiece.SetActive(false);
            }
            else if (m_TargetCell.m_BelongTo == Player.Red)
            {
                m_RedPiece.SetActive(true);
                m_BluePiece.SetActive(false);
            }
        }
        else
        {
            m_BluePiece.SetActive(false);
            m_RedPiece.SetActive(false);
        }
    }

    public void DisplayText(string text, Player player)
    {
        if (!string.IsNullOrEmpty(text))
        {
            m_Text.color = player == Player.Blue ? Color.blue : Color.red;
            m_Text.text = text;
        }
        else
        {
            m_Text.text = "";
        }
    }

    public void OnClick()
    {
        //Debug.Log($"click {m_TargetCell.m_Pos}");
        m_GameUI.Place(m_TargetCell.m_Pos);
    }
}